/* GSOrderApplyViewAction.java
 *
 * Project/Product: GWBS2009
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   Administrator	2009-3-26	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2009
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.action;

import java.util.ArrayList;

import system.LoginContext;

import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.business.GSOrderApplyProcessor;
import com.hitrust.gs.business.GSOrderProcessor;
import com.hitrust.gs.business.GSUniteGwProcessor;
import com.hitrust.gs.dao.GSOrderDAO;
import com.hitrust.gs.form.GSBusOrderCancelListForm;
import com.hitrust.gs.form.GSOrderDetailQueryForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.page.ResultProcess;
import com.hitrust.gs.vo.GSBusOrderCancelVO;

public class GSOrderApplyViewAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    private GSOrderApplyProcessor applyPro=new GSOrderApplyProcessor();
    public String execute(GSBaseForm aForm) throws Exception {
        GSBusOrderCancelListForm tForm = (GSBusOrderCancelListForm)aForm;
        GSBusOrderCancelVO tGSBusOrderCancelVO=new GSBusOrderCancelVO();
        tGSBusOrderCancelVO.orderid = tForm.orderdetailId;
        tGSBusOrderCancelVO.orderDeptId = tForm.orderDeptId;
        tGSBusOrderCancelVO.manufInfo = tForm.manufInfo;
        tGSBusOrderCancelVO.concentricityId = tForm.concentricityId;
        tGSBusOrderCancelVO.orderCreateDateStr = tForm.orderCreateDateStr;
        tGSBusOrderCancelVO.orderCreateDateEnd = tForm.orderCreateDateEnd;
        tGSBusOrderCancelVO.orderDetailStatus = tForm.orderStatus;
        tGSBusOrderCancelVO.providerId = tForm.providerId;
        tGSBusOrderCancelVO.manufType1 = tForm.manuftype1;
        tGSBusOrderCancelVO.manufType2 = tForm.manuftype2;
        tGSBusOrderCancelVO.manufType3 = tForm.manuftype3;
        try{
//          巴士物资级操作员可操作订货单位及送货地址
            LoginContext context = (LoginContext)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            GSUniteGwProcessor unitePro=new GSUniteGwProcessor();
            ArrayList wareList=unitePro.getWareHouseLevelName(context.getLoginWarehouseCode(), context.getLoginWarehouseCode());
            aForm.getRequest().setAttribute("orderdept",wareList);
            
            String[] tStr = this.getPageParams(tForm,tGSBusOrderCancelVO);
            tForm.getRequest().setAttribute("pageSize",tStr[1]);
            tForm.getRequest().setAttribute("totalRecords",tStr[2]);
            ArrayList tList = applyPro.getAllOrderApplyByPage(tGSBusOrderCancelVO, Integer.parseInt(tStr[0]),Integer.parseInt(tStr[1]));
            ResultProcess tRsProc = new ResultProcess();
            tRsProc.setResult(tList);
            tForm.getRequest().setAttribute("order",tRsProc);
            aForm.getRequest().setAttribute("orderStatus",tForm.orderStatus);
            
            //种类等级
            GSManufactureProcessor tGSManufProcessor = new GSManufactureProcessor();
            tGSManufProcessor.getManufactureOfLevel(aForm);
            aForm.getRequest().setAttribute("requery","false");
        }
        catch(Exception e){
            tForm.getRequest().setAttribute("action","A150501.do");
            throw e;
        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }
    
    private String[] getPageParams(GSBusOrderCancelListForm aForm,GSBusOrderCancelVO tGSBusOrderCancelVO) throws Exception{
        String tStr[] = new String[3];
        int totalRecords;
        int pageNo;
        int pageSize;
        String tPage = GSBaseConstants.tPage;
        //根据页面传入的查询参数查询订单信息
        if(aForm.getChoice() == null || aForm.getChoice().equals("")){
            totalRecords = applyPro.getAllOrderApplyCount(tGSBusOrderCancelVO);
            
            // 取得系统默认的页大小
            pageSize = Integer.parseInt(tPage);
            // PageNo=1
            pageNo = 1;
            int n = (totalRecords % pageSize == 0 )? totalRecords / pageSize:totalRecords / pageSize + 1;
            if (pageNo>n) {
                pageNo=n;
            }
            tStr[0] = "" + pageNo;
            tStr[1] = "" + pageSize;
            tStr[2] = "" + totalRecords;
        }else{
            tStr = GSBaseManager.getPageNoAndPageSize(aForm);
        }
        return tStr;
    }
}
